﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com.DA;
using Com.BU;
using Com.GUI.LibraryManager.Controls.SubControl;

namespace Com
{
    /// <summary>
    /// Interaction logic for ucColdStorageProduct.xaml
    /// </summary>
    public partial class ucColdStorageProduct : UserControl
    {
        ucColdStorageProductDetail ucProduct = new ucColdStorageProductDetail();
        ucColdStorageLoadingStandard ucLoadingStandard = new ucColdStorageLoadingStandard();
        ucColdStorageEnthalpy ucStorageEnthalpy = new ucColdStorageEnthalpy();

        public ucColdStorageProduct()
        {
            this.InitializeComponent();


        }


        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                if (ucProduct.saveData())
                {
                    enableButtons();
                }
               
                
            }
            if (cbxDescription.SelectedIndex == 1)
            {

                if (ucStorageEnthalpy.saveData())
                {
                    enableButtons();
                }
                
            }
            if (cbxDescription.SelectedIndex == 2)
            {
                ucLoadingStandard.saveData();
                enableButtons();
            }
        }


        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                disableButtons();
                ucProduct.addNew();
            }
            if (cbxDescription.SelectedIndex == 1)
            {
                disableButtons();
                ucStorageEnthalpy.addNew();
            }
            if (cbxDescription.SelectedIndex == 2)
            {
                ucLoadingStandard.newData();
                disableButtons();
            }

        }

        private void btnCopy_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                ucProduct.copyData();
                disableButtons();
            }
            if (cbxDescription.SelectedIndex == 1)
            {
                ucStorageEnthalpy.copyData();
                disableButtons();
            }
            if (cbxDescription.SelectedIndex == 2)
            {
                
            }

        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                ucProduct.delData();
                ucLoadingStandard.loadData();
            }
            if (cbxDescription.SelectedIndex == 1)
            {
                ucStorageEnthalpy.delData();
            }
            if (cbxDescription.SelectedIndex == 2)
            {
                ucLoadingStandard.delData();
            }


        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                ucProduct.reLoad();
                enableButtons();
            }
            if (cbxDescription.SelectedIndex == 1)
            {
                ucStorageEnthalpy.reload();
                enableButtons();
            }
            if (cbxDescription.SelectedIndex == 2)
            {
                ucLoadingStandard.loadData();
                enableButtons();
            }

        }

        private void cbxDescription_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            dockPanel1.Children.Clear();
            if (cbxDescription.SelectedIndex == 0)
            {
                dockPanel1.Children.Add(ucProduct);
            }
            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(ucStorageEnthalpy);
            }
            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(ucLoadingStandard);
            }
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            cbxDescription.SelectedIndex = 0;
            enableButtons();
        }



        private void enableButtons()
        {
            btnSave.IsEnabled = false;
            btnCancel.IsEnabled = false;

            btnNew.IsEnabled = true;
            btnCopy.IsEnabled = true;
            btnDelete.IsEnabled = true;


        }
        private void disableButtons()
        {
            btnSave.IsEnabled = true;
            btnCancel.IsEnabled = true;

            btnNew.IsEnabled = false;
            btnCopy.IsEnabled = false;
            btnDelete.IsEnabled = false;

        }





    }
}